﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace G.Document
{
    public class HtmlToXAML
    {
        public static void Convert(string html)
        {
            System.Xml.Linq.XElement xe = System.Xml.Linq.XElement.Parse(html);
            Replace(xe);

            //string str = html;
            //str = str.Replace("p>", "Span>");
            //str = str.Replace("strong>", "Bold>");
      
        }

        private static void Replace(System.Xml.Linq.XElement xe)
        {
            foreach (var item in xe.Elements())
            {
                switch (item.Name.LocalName)
                {
                    case "p":
                        item.Name = "Paragraph";
                        break;
                    case "strong":
                        item.Name = "Bold";
                        break;
                    case "br":
                        item.Name = "LineBreak";
                        break;
                    case "a":
                        item.Name = "Paragraph";
                        if (item.HasAttributes)
                            item.RemoveAttributes();
                        break;
                    default:
                        break;
                }

                if (item.NodeType == System.Xml.XmlNodeType.Element && item.HasElements)
                    Replace(item);
            }
        }
    }
}
